package restless.core.managers {
	
	import flash.geom.Point;
	import restless.core.gameObjs.RLEUpdateRenderObj;
	import restless.core.interfaces.ICheckColisions;
	import restless.core.RLEColision;
	import restless.core.interfaces.IColisionable;
	import restless.utilities.Benchmark;
	
	public class RLEColisionManager extends RLEUpdateRenderObj {
		
		private var vIds:Vector.<String> = new Vector.<String>;
		private var vColision:Vector.<ICheckColisions> = new Vector.<ICheckColisions>;
		private var i:int;
		
		public function RLEColisionManager() {
			setRE();
		} 
		
		public function createColision(playAreaW:int, playAreaH:int, minGridSize:int, minHitBoxSize:int, id:String = "default", pixelBased:Boolean = false, customColision:Class = null, ...args):void {
			vIds.push(id);
			if(customColision == null) {
				vColision.push(new RLEColision(playAreaW, playAreaH, minGridSize, minHitBoxSize, pixelBased));
			} else {
				vColision.push(new customColision(playAreaW, playAreaH, minGridSize, minHitBoxSize, pixelBased, args));
			}
		}
		
		public function pauseColision(bool:Boolean, id:String = "default"):void {
			i = vIds.indexOf(id);
			vColision[i].pause = bool;
		}
		
		public function addColItem(asset:IColisionable, colision:String):void {
			i = vIds.indexOf(colision);
			vColision[i].addColItem(asset);
		}
		
		public function removeColItem(asset:IColisionable, colision:String = "default"):void { 
			i = vIds.indexOf(colision);
			
			if (colision != "default") {
				vColision[0].removeColItem(asset);
			} else {
				
				vColision[i].removeColItem(asset);
			}
		}
		
		override public function update():void {
			i = vColision.length - 1;
			for (i; i > -1; i--) {
				vColision[i].collide();
			}
		}
	}
}